home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS14.ADF
/
Tool
/
display.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-01-28
|
12KB
|
445 lines
/*
DISPLAY.C Copyright Daniel D. Kary 1986
Standard Listing
*/
#include <exec/types.h>
#include <exec/tasks.h>
#include <exec/libraries.h>
#include <exec/devices.h>
#include <graphics/copper.h>
#include <graphics/display.h>
#include <graphics/text.h>
#include <graphics/view.h>
#include <graphics/gels.h>
#include <graphics/regions.h>
#include <hardware/blit.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <stdio.h>
#include <libraries/dos.h>
#include <workbench/workbench.h>
/* Resource Flag definitions */
#define F_INTUITION 0x000001
#define F_GRAPHICS 0x000002
#define F_WRITE_PORT 0x000004
#define F_WRITE_MSG 0x000008
#define F_WINDOW 0x000010
#define F_CONSOLE 0x000020
/* Menu definitions */
#define MENU_PROJECT 0
#define ITEM_HEIGHT 10
/* for the PROJECT Menu ... */
#define PROJECT_TOP 0
#define PROJECT_BOTTOM 1
#define PROJECT_UP 2
#define PROJECT_DOWN 3
#define PROJECT_WIDTH 120
#define PROJECT_BAR 75
/* for the DATA Menu's ... */
#define DATA_BAR 40
#define DATA_WIDTH 95
#define DATA_LEFT (-60)
#define MAXHEADINGS 14
#define MAXLINES 18
#define MAXITEMS (MAXHEADINGS * MAXLINES)
struct Text {
/* linked list of lines of text */
struct Text *next;
char *line;
};
struct X_MenuItem {
/* expanded MenuItem, Includes a pointer to user data */
struct X_MenuItem *NextItem;
SHORT LeftEdge, TopEdge;
SHORT Width, Height;
USHORT Flags;
LONG MutEx;
APTR ItemFill;
APTR SFill;
BYTE Command;
struct MenuItem *SubItem;
USHORT Select;
struct Text *text;
};
struct IntuiText ProjectText =
{
0, 1, JAM1, /* front, back, mode */
1, 1, /* left, top */
NULL, /* font */
"RE-DISPLAY",
NULL, /* next */
};
struct MenuItem Project =
{
NULL, /* next */
0, ITEM_HEIGHT * 0, /* select box left, top */
PROJECT_WIDTH, /* select box width */
ITEM_HEIGHT, /* select box height */
ITEMTEXT | COMMSEQ | ITEMENABLED | HIGHCOMP,
/* flags */
0, /* mutual exclude */
(APTR)&ProjectText, /* text */
NULL, /* select image */
'R', /* command */
NULL, /* subitem */
NULL, /* next select */
};
struct Menu MainMenu =
{
NULL, /* next menu */
5, 0, /* select left, top */
75, 10, /* select width, height */
MENUENABLED, /* flags */
"Project", /* text */
&Project, /* first item */
0, 0, 0, 0, /* mystery variables */
};
struct NewWindow nw =
{
0,0, /* left, top */
640,200, /* width, height */
-1,-1, /* detail pen, block pen */
CLOSEWINDOW | MOUSEBUTTONS | MENUPICK,
/* IDCMP Flags */
WINDOWDEPTH | WINDOWSIZING | WINDOWDRAG |
ACTIVATE | SMART_REFRESH | WINDOWCLOSE,
/* gadget flags */
NULL, /* user gadgets */
NULL, /* user check */
"Structure Display", /* title */
NULL, /* screen */
NULL, /* super bitmap */
100,45, /* min width, min height */
640,200, /* max width, max height */
WBENCHSCREEN /* screen type */
};
struct X_MenuItem X_MenuTemplate =
{
NULL, /* next */
DATA_LEFT, 0, /* left, top */
DATA_WIDTH, ITEM_HEIGHT,/* width, height */
ITEMTEXT | ITEMENABLED | HIGHCOMP,
/* flags */
0, NULL, NULL, /* MutEx, Fills */
' ', NULL, /* Command, subitem */
NULL, NULL /* Next, Text List */
};
struct Menu MenuTemplate =
{
NULL, /* next */
0, 0, /* left, top */
DATA_BAR, ITEM_HEIGHT, /* width, height */
MENUENABLED, /* flags */
NULL, NULL, /* text, first item */
0,0,0,0 /* mystery variables */
};
extern struct IOStdReq *CreateStdIO();
extern struct MsgPort *CreatePort();
struct Window *w;
struct IntuiMessage *message;
struct IOStdReq *WriteMsg;
struct MsgPort *WritePort;
struct Text *current_text = NULL;
struct X_MenuItem *head = NULL;
struct X_MenuItem *temp = NULL;
struct Text *first = NULL;
struct Text *t = NULL;
int Items = 0;
ULONG GfxBase;
ULONG IntuitionBase;
int cur_resource = NULL;
main(argc, argv)
int argc;
char *argv[];
{
int i, class, code;
struct X_MenuItem *p;
if(argc < 2){
printf("USAGE: %s file(s)\n", argv[0]);
exit(1);
}
if((GfxBase = OpenLibrary("graphics.library",0)) == NULL)
abort("Can't open graphics.library");
cur_resource |= F_GRAPHICS;
if((IntuitionBase =
OpenLibrary("intuition.library",0)) == NULL)
abort("Can't open intuition.library");
cur_resource |= F_INTUITION;
if((WritePort = CreatePort("con.write",0)) == 0)
abort("Can't create console write port");
cur_resource |= F_WRITE_PORT;
if((WriteMsg = CreateStdIO(WritePort)) == 0)
abort("Can't create console write message");
cur_resource |= F_WRITE_MSG;
if((w = (struct Window *) OpenWindow(&nw)) == NULL)
abort("Can't open new window");
cur_resource |= F_WINDOW;
WriteMsg->io_Data = (APTR) w;
WriteMsg->io_Length = sizeof(*w);
if((OpenDevice("console.device", 0, WriteMsg, 0)) != 0)
abort("Can't open console");
cur_resource |= F_CONSOLE;
PutStr(WriteMsg,"\033[0 p"); /* turn the cursor off */
PutStr(WriteMsg, "Reading Data File(s), Please Wait.\n");
for(i = 1; i < argc; i++)
read_file(argv[i]);
build_menu();
PutChar(WriteMsg, 0x0c); /* clear the screen */
SetMenuStrip(w, &MainMenu);
while(1){
Wait(-1);
while(message = (struct IntuiMessage *)
GetMsg(w->UserPort)){
class = message->Class;
code = message->Code;
ReplyMsg(message);
if(class == CLOSEWINDOW){
abort("Bye!");
}
if(class == MENUPICK){
switch MENUNUM(code){
case NOMENU:
break;
case MENU_PROJECT:
redisplay();
break;
default:
p = (struct X_MenuItem *)
ItemAddress(&MainMenu, code);
current_text = p->text;
redisplay();
break;
}
}
}
}
}
abort(s)
char *s;
{
if (cur_resource & F_CONSOLE)
CloseDevice(WriteMsg);
if (cur_resource & F_WINDOW){
ClearMenuStrip(w);
CloseWindow(w);
}
if (cur_resource & F_WRITE_MSG)
DeleteStdIO(WriteMsg);
if (cur_resource & F_WRITE_PORT)
DeletePort(WritePort);
if (cur_resource & F_GRAPHICS)
CloseLibrary(GfxBase);
if (cur_resource & F_INTUITION)
CloseLibrary(IntuitionBase);
printf("%s\n",s);
exit(0);
}
redisplay()
{
int i, class, code;
struct Text *t;
i = 0;
t = current_text;
PutChar(WriteMsg, 0x0c); /* clear the screen */
while(t){
if(message = (struct IntuiMessage *)
GetMsg(w->UserPort)){
class = message->Class;
code = message->Code;
ReplyMsg(message);
if(class == MOUSEBUTTONS)
if(code == SELECTDOWN)
return(0);
}
PutStr(WriteMsg, t->line);
t = t->next;
if(i++ > 16) Delay(3);
}
}
read_file(s)
char *s;
{
FILE *fp;
char buf[256];
struct IntuiText *it;
if((fp = fopen(s, "r")) == NULL){
sprintf(&buf[0],"Unable to read %s\n", s);
PutStr(WriteMsg, &buf[0]);
Delay(120);
return(0);
}
while((fgets(&buf[0], 256, fp)) != NULL){
if(buf[0] == '!'){
buf[(strlen(&buf[0])-1)] = '\0';
if(Items == MAXITEMS){
sprintf(&buf[0],
"MAXITEMS exceeded in %s\r\n", s);
PutStr(WriteMsg, &buf[0]);
fclose(fp);
Delay(120);
return(0);
}
Items++;
temp = (struct X_MenuItem *)
myalloc(sizeof(struct X_MenuItem));
*temp = X_MenuTemplate;
temp->ItemFill = (APTR)
myalloc(sizeof(struct IntuiText));
it = (struct IntuiText *) temp->ItemFill;
*it = ProjectText;
it->IText = (UBYTE *) myalloc(12);
first = NULL;
strncpy(it->IText, &buf[1], 11);
insert(temp);
}
else if(temp){
t = (struct Text *) myalloc(sizeof(struct Text));
t->line = (char *) myalloc(strlen(&buf[0])+1);
strcpy(t->line, &buf[0]);
t->next = NULL;
if(first)
first->next = t;
else
temp->text = t;
first = t;
}
}
fclose(fp);
temp = NULL;
first = NULL;
}
build_menu()
{
int i, j, headings, items;
struct Menu *m;
struct IntuiText *t;
if(Items <= MAXHEADINGS){
headings = Items;
items = 1;
}
else{
headings = MAXHEADINGS;
items = Items/(MAXHEADINGS - 1);
}
m = &MainMenu;
for(i = 0; i < headings; i++){
if(head){
m->NextMenu = (struct Menu *)
myalloc(sizeof(struct Menu));
m = m->NextMenu;
*m = MenuTemplate;
m->LeftEdge = PROJECT_BAR + (DATA_BAR * i);
m->MenuName = (BYTE *) myalloc(4);
m->FirstItem = (struct MenuItem *) head;
t = (struct IntuiText *) head->ItemFill;
strncpy(m->MenuName, t->IText, 3);
}
else return(0);
if(i == (headings - 1))
items = MAXLINES;
for(j = 0; j < items; j++){
head->TopEdge = ITEM_HEIGHT * j;
temp = head;
head = head->NextItem;
if(head == NULL)
return(0);
if(j == (items - 1))
temp->NextItem = NULL;
}
}
}
insert(p)
struct X_MenuItem *p;
{
struct X_MenuItem *t1, *t2;
struct IntuiText *s1, *s2;
s1 = (struct IntuiText *) p->ItemFill;
if(head){
t1 = head;
t2 = NULL;
while(t1){
s2 = (struct IntuiText *) t1->ItemFill;
if((strcmp(s1->IText, s2->IText)) <= 0){
p->NextItem = t1;
if(t2 == NULL)
head = p;
else
t2->NextItem = p;
return(0);
}
t2 = t1;
t1 = t1->NextItem;
}
t2->NextItem = p;
}
else
head = p;
}
PutStr(r, s)
struct IOStdReq *r;
char *s;
{
r->io_Command = CMD_WRITE;
r->io_Data = (APTR) s;
r->io_Length = -1;
DoIO(r);
return(0);
}
PutChar(r, c)
struct IOStdReq *r;
char c;
{
r->io_Command = CMD_WRITE;
r->io_Data = (APTR) &c;
r->io_Length = 1;
DoIO(r);
return(0);
}
myalloc(n)
int n;
{
int i;
i = malloc(n);
if(i == 0)
abort("Insufficient Memory");
return(i);
}